/*
 * Copyright (c) 2001, 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.api.internal;

import java.util.Map;

import net.sourceforge.perforce.api.IClientUserDelegate;
import net.sourceforge.perforce.api.IError;

/**
  * Wrapper class for Perforce API ClientUser class.
  * 
  * @version $Revision: 41 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net>Boris Pruessmann</a>
  */
public final class ClientUser
{
	// --------------------------------------------------------------------------- Private Variables
	
	/** Used to store the native reference.
	  * <br>DON'T TOUCH THE CONTENT OF THIS VARIABLE 
	  */
	private int _nativeHandle;
		
	/** Stores instance of IClientUserDelegate used as delegate of this
	  * ClientUser object.
	  */
	private IClientUserDelegate delegate;
	
	// -------------------------------------------------------------------------------- Constructors
	
	/** Constructor for ClientUser.
	  * @param delegate IClientUserDelegate to be used.
	  */
	ClientUser(IClientUserDelegate delegate)
	{
		construct();
		this.delegate = delegate;
	}

	// ---------------------------------------------------------- Public Methods

	/** Destroys the native ClientUser. */
	public void dispose() 
	{
		this.delegate = null;
		destruct();
	}

	/** Delegates callback to IClientUserDelegate.inputData. 
	  * 
	  * @param error to be filled in error case.
	  * @return data used as input for '-i' commands.
	  */
	public String inputData(IError error)
	{
		return delegate.inputData(error);
	}

	/** Delegates callback to IClientUserDelegate.outputError. 
	  * 
	  * @param errorString Error message provided by Perforce ClientApi API.
	  */
	public void outputError(String errorString)
	{
		delegate.outputError(errorString);
	}

	/** Delegates callback to IClientUserDelegate.outputInfo. 
	  * 
	  * @param level level of info message.
	  * @param infoString Info message provided by Perforce ClientApi API.
	  */
	public void outputInfo(char level, String infoString)
	{
		delegate.outputInfo(level, infoString);
	}

	/** Delegates callback to IClientUserDelegate.outputBinary.
	  * 
	  * @param data binary data.
	  */
	public void outputBinary(byte[] data)
	{
		delegate.outputBinary(data);
	}

	/** Delegates callback to IClientUserDelegate.outputText. 
	  *
	  * @param data text data.
	  */
	public void outputText(byte[] data)
	{
		delegate.outputText(data);
	}

	/** Delegates callback to IClientUserDelegate.outputStat. 
	  * 
	  * @param data Map as result of commands like fstat.
	  */
	public void outputStat(Map data)
	{
		delegate.outputStat(data);
	}

	/** Delegates callback to IClientUserDelegate.handleError. 
	  * 
	  * @param error Error data to be processed as a result of a failed
	  *         operation.
	  */
	public void handleError(IError error)
	{
		delegate.handleError(error);
	}

	/** Delegates callback to IClientUserDelegate.message. 
	  * 
	  * @param error Error data to be processed as a result of a failed
	  *         operation.
	  */
	public void message(IError error)
	{
		delegate.message(error);
	}

	/** Delegates callback to IClientUserDelegate.resolve. 
	  * 
	  * @param clientMerge ClientMerge used for resolved operation.
	  */
	public void resolve(ClientMerge clientMerge)
	{	
		// TODO:
		throw new UnsupportedOperationException();	
	}

	/** Delegates callback to IClientUserDelegate.prompt. 
	  *
	  * @param msg -
	  * @param noEcho -
	  * @param error -
	  * @return user provided answer to prompt operation.
	  */
	public String prompt(String msg, boolean noEcho, Error error)
	{
		// TODO:
		throw new UnsupportedOperationException();
	}
	
	/** Delegates callback to IClientUserDelegate.finished. */
	public void finished()
	{
		delegate.finished();
	}

	// ----------------------------------------------------------------------------- Private Methods

	/** Creates the native ClientUser object. */
	private native void construct();

	/** Destroys the native ClientUser object. */
	private native void destruct();
}